﻿using BW.MLTT.IRepository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BW.MLTT.Repository
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        private readonly MLTTDbContext _db;

        public BaseRepository(MLTTDbContext db)
        {
            _db = db;
        }

        public void Add(T entity)
        {
            _db.Set<T>().Add(entity);
        }

        public void AddRange(List<T> entity)
        {
            _db.Set<T>().AddRange(entity);
        }

        public void Delete(T entity)
        {
           _db.Set<T>().Remove(entity);
        }

        public void DeletedRange(List<T> entity)
        {
            _db.Set<T>().RemoveRange(entity);
        }

        public IQueryable<T> GetAll()
        {
            return _db.Set<T>().AsNoTracking();
        }

        public int SaveChange()
        {
            return _db.SaveChanges();
        }

        public void Update(T entity)
        {
            _db.Set<T>().Update(entity);
        }

        public void UpdateRange(List<T> entity)
        {
            _db.Set<T>().UpdateRange(entity);
        }
    }
}
